x86/VPMU: Clear last_vcpu when destroying VPMU
authorBoris Ostrovsky <boris.ostrovsky@oracle.com>
Wed, 7 Jan 2015 10:12:27 +0000 (11:12 +0100)
committerJan Beulich <jbeulich@suse.com>
Wed, 7 Jan 2015 10:12:27 +0000 (11:12 +0100)
commited8017155607db1bbe1f6ca41eac696b7ef8082b
tree1e26ff71989657c2631253e06c4a670756218985
parente293dd6e80bc6e624d6222ae13331958eb47116a
x86/VPMU: Clear last_vcpu when destroying VPMU

We need to make sure that last_vcpu is not pointing to VCPU whose
VPMU is being destroyed. Otherwise we may try to dereference it in
the future, when VCPU is gone.

We have to do this via IPI since otherwise there is a (somewheat
theoretical) chance that between test and subsequent clearing
of last_vcpu the remote processor (i.e. vpmu->last_pcpu) might do
both vpmu_load() and then vpmu_save() for another VCPU. The former
will clear last_vcpu and the latter will set it to something else.

Performing this operation via IPI will guarantee that nothing can
happen on the remote processor between testing and clearing of
last_vcpu.

We should also check for VPMU_CONTEXT_ALLOCATED in vpmu_destroy() to
avoid unnecessary percpu tests and arch-specific destroy ops. Thus
checks in AMD and Intel routines are no longer needed.

Signed-off-by: Boris Ostrovsky <boris.ostrovsky@oracle.com>
Acked-by: Kevin Tian <kevin.tian@intel.com>
xen/arch/x86/hvm/svm/vpmu.c
xen/arch/x86/hvm/vmx/vpmu_core2.c
xen/arch/x86/hvm/vpmu.c